#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sets import Set

combination = Set()

def digitPower(x,power):
    xStr=str(x)
    sum=0
    for digit in xStr:
        sum += pow(int(digit),power)
    return sum


for x in range (2,9999):
    if x==digitPower(x,4):
        print x

powSum=0
for x in range (2,999999):
    if x==digitPower(x,5):
        print x
        powSum += x

print powSum

    


